import Toast from 'tdesign-miniprogram/toast/index';

Component({
  externalClasses: ['wr-class'],
  properties: {
    cartGoodsList: {
      type: Array,
      value: []
    },
    thumbWidth: { type: null },
    thumbHeight: { type: null },
    storeChecked: {
      type: Boolean,
      value: false,
    },
  },

  data: {
    storeName: wx.getStorageSync('shopInfo').Name,
  },

  methods: {
    // 删除商品
    deleteGoods(e) {
      const { goods } = e.currentTarget.dataset;
      this.triggerEvent('delete', { goods });
    },

    // 选中商品
    selectGoods(e) {
      const { goods } = e.currentTarget.dataset;
      this.triggerEvent('selectGoods', {
        goods
      });
    },

    changeStepper(e) {
      let { value } = e.detail;
      const { goods } = e.currentTarget.dataset;
      value = parseInt(value)
      if(isNaN(value)){
        value = 1
      }
      this.triggerEvent('changeQuantity', {
        goods,
        quantity: value,
      });
    },

    // 选中门店
    checkedStore(e) {
      this.triggerEvent('selectStore');
    },

    goGoodsDetail({currentTarget}) {
      const goodsId = currentTarget.dataset.goods.GoodsId
      wx.navigateTo({
        url: '/pages/detail/detail?id=' + goodsId,
      })
      // const { goods } = e.currentTarget.dataset;
      // this.triggerEvent('goodsClick', { goods });
    },

    gotoCoupons() {
      wx.navigateTo({ url: '/pages/coupon/coupon?couponType=0'});
    },
  },
});
